package cn.com.xy.sms.sdk.util;

import java.util.Map;

/* SDK-428 qujingqiang 20160530 start */
public class PriorityUtils {

	 /**
     * 选择联盟优先级
     *
     * @param unionStr
     * @param userKey
     * @param priorityMap
     * @return
     */
    public static String findPriority(String unionStr, String userKey, Map<String, String> priorityMap) {
        int mod = stringToNumber(unionStr, userKey);

        return priorityMap.get(unionStr + mod);
    }

    private static int stringToNumber(String unionStr, String msg) {
        int mod;
        switch (unionStr.length()) {
            case 1: {
                mod = 1;
                break;
            }
            case 2: {
                mod = 2;
                break;
            }
            case 3: {
                mod = 6;
                break;
            }
            case 4: {
                mod = 24;
                break;
            }
            default: {
                mod = 1;
            }
        }
        int total = 0;
        for(int i = 0; i < msg.length(); i++){
            total += msg.charAt(i);
        }

        return total % mod;
    }

}
/* SDK-428 qujingqiang 20160530 end */